#include<cstdio>
#include<queue>
#include<iostream>
using namespace std;

typedef unsigned long long ull;

int main(){
	int n;
	ull a;
	while(scanf("%d",&n)!=EOF&&n){
		queue<ull>M;
		M.push(1);
		while(!M.empty())
		{
			a=M.front();
			M.pop();
			if(a%n==0)
			break;
			ull b=a*10;
			M.push(b);
			b++;
			M.push(b);
		}
		printf("%lld\n",a);
	}
	return 0;
}